home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / main9.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  3KB  |  147 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32.  
  33. bytes(name,total,block)
  34. char *name;
  35. int *total,*block;
  36. {
  37.     int free=-1;
  38.     BPTR mylock,testlock;
  39.     struct InfoData __aligned infodata;
  40.  
  41.     if (!(mylock=Lock(name,ACCESS_READ))) {
  42.         *total=0; *block=0;
  43.         return(0);
  44.     }
  45.     Info(mylock,&infodata);
  46.     if (ramdisk_lock) {
  47.         testlock=DupLock(mylock);
  48.         testlock=getrootlock(testlock);
  49.         if (CompareLock(testlock,ramdisk_lock)==LOCK_SAME) free=AvailMem(0);
  50.         UnLock(testlock);
  51.         if (free>-1) {
  52.             *total=free;
  53.             *block=free/infodata.id_BytesPerBlock;
  54.             UnLock(mylock);
  55.             return(free);
  56.         }
  57.     }
  58.     *total=infodata.id_BytesPerBlock*infodata.id_NumBlocks;
  59.     free=*total-(infodata.id_BytesPerBlock*infodata.id_NumBlocksUsed);
  60.     *block=infodata.id_NumBlocks-infodata.id_NumBlocksUsed;
  61.     UnLock(mylock);
  62.     return(free);
  63. }
  64.  
  65. struct TagItem obtain_tags[]={
  66.     {OBP_Precision,PRECISION_EXACT},
  67.     {OBP_FailIfBad,TRUE},
  68.     {TAG_DONE,0}};
  69.  
  70. void get_colour_table()
  71. {
  72.     int a;
  73.  
  74.     for (a=0;a<16;a++) {
  75.         screen_pens[a].red=config->new_palette[(a*3)];
  76.         screen_pens[a].green=config->new_palette[(a*3)+1];
  77.         screen_pens[a].blue=config->new_palette[(a*3)+2];
  78.         screen_pens[a].pen=a;
  79.         screen_pens[a].alloc=0;
  80.     }
  81.  
  82.     if (system_version2>=OSVER_39) {
  83.         int num;
  84.         struct ColorMap *cm;
  85.  
  86.         num=1<<config->scrdepth;
  87.         cm=Window->WScreen->ViewPort.ColorMap;
  88.  
  89.         for (a=0;a<num;a++) {
  90.             if ((screen_pens[a].pen=
  91.                 ObtainBestPenA(cm,
  92.                     screen_pens[a].red,
  93.                     screen_pens[a].green,
  94.                     screen_pens[a].blue,
  95.                     (MainScreen)?obtain_tags:NULL))==-1) {
  96.                     screen_pens[a].pen=FindColor(cm,
  97.                         screen_pens[a].red,
  98.                         screen_pens[a].green,
  99.                         screen_pens[a].blue,
  100.                         -1);
  101.                 }
  102.                 else screen_pens[a].alloc=1;
  103.         }
  104.     }
  105. }
  106.  
  107. void free_colour_table()
  108. {
  109.     if (system_version2>=OSVER_39) {
  110.         int a;
  111.         struct ColorMap *cm;
  112.  
  113.         cm=Window->WScreen->ViewPort.ColorMap;
  114.  
  115.         for (a=0;a<16;a++) {
  116.             if (screen_pens[a].alloc) {
  117.                 ReleasePen(cm,screen_pens[a].pen);
  118.                 screen_pens[a].alloc=0;
  119.             }
  120.         }
  121.     }
  122. }
  123.  
  124. void SetDrawModes(r,fg,bg,mode)
  125. struct RastPort *r;
  126. char fg,bg,mode;
  127. {
  128.     if (system_version2>=OSVER_39) {
  129.         SetABPenDrMd(r,
  130.             screen_pens[fg].pen,
  131.             screen_pens[bg].pen,
  132.             mode);
  133.     }
  134.     else {
  135.         SetAPen(r,screen_pens[fg].pen);
  136.         SetBPen(r,screen_pens[bg].pen);
  137.         SetDrMd(r,mode);
  138.     }
  139. }
  140.  
  141. void do3dbox(r,x,y,w,h)
  142. struct RastPort *r;
  143. int x,y,w,h;
  144. {
  145.     Do3DBox(r,x,y,w,h,screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  146. }
  147.